#include <iostream>

using namespace std;
const int N = 1e5 + 10;
int f[N], a[N];
int len;
int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++)
	{
		if (len == 0 || a[i] > f[len]) f[++len] = a[i];
		int l = 1, r = len;
		// 4  5   8  9 19
		while (l < r)
		{
			int mid = (l + r) / 2;
			if (f[mid] >= a[i]) r = mid;
			else l = mid + 1;
		}
		f[r] = a[i];
	}
	cout << len << endl;

	return 0;
}